package com.sunny.example.string;

import java.util.Scanner;

public class StringTest {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
//            String input = scanner.nextLine();
//            calcCoor(input);
//            checkPWD(input);
            encryptStr(scanner);
        }
    }

    /**
     * 字符串圆角密
     *
     * @param scanner
     */
    private static void encryptStr(Scanner scanner) {
        String[] strs = new String[2];
        for (int i = 0; i < 2; i++) {
            strs[i] = scanner.nextLine();
        }
        String str1 = strs[0];
        String str2 = strs[1];
        StringBuffer encryptedSB = new StringBuffer();
        StringBuffer decryptedSB = new StringBuffer();
        for (char c : str1.toCharArray()) {
            char tmp = c;
            if (Character.isLowerCase(c)) {//小写 + 1 转大写
                tmp = (char) Character.toUpperCase(c == 'z' ? 'a' : c + 1);
                encryptedSB.append(tmp);
            } else if (Character.isUpperCase(c)) {//大写 +1 转小写
                tmp = (char) Character.toLowerCase(c == 'Z' ? 'A' : c + 1);
                encryptedSB.append(tmp);
            } else if (Character.isDigit(c)) {
                int i =  Integer.parseInt(String.valueOf(c))== 9 ? 0 : Integer.parseInt(String.valueOf(c)) + 1;
                encryptedSB.append(i);
            }
        }
        //解密
        for (char c : str2.toCharArray()) {
            char tmp2 = c;
            if (Character.isLowerCase(c)) {//小写 -1 转大写
                tmp2 = (char) Character.toUpperCase(c == 'a' ? 'z' : c - 1);
                decryptedSB.append(tmp2);
            } else if (Character.isUpperCase(c)) {//大写 -1 转小写
                tmp2 = (char) Character.toLowerCase(c == 'A' ? 'Z' : c - 1);
                decryptedSB.append(tmp2);
            } else if (Character.isDigit(c)) {
                int i = Integer.parseInt(String.valueOf(c)) == 0 ? 9 : Integer.parseInt(String.valueOf(c)) - 1;
                decryptedSB.append(i);
            }
        }

        System.out.println(encryptedSB.toString());
        System.out.println(decryptedSB.toString());

    }

    /**
     * 校验密码
     *
     * @param input
     */
    private static void checkPWD(String input) {
        String regex = "^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?![a-z0-9]+$)(?![0-9A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{8,}$";
        if (input.matches(regex)) {
//            System.out.println("OK");
            //再判断是否有长度为3及以上的子串
            if (checkSubStr(input, 0, 3)) {
                System.out.print("NG");
            } else {
                System.out.print("OK");
            }
        } else {
            System.out.print("NG");
        }

    }

    /**
     * 检测是否有重复子串
     * 采用递归
     *
     * @param input
     * @return
     */
    private static boolean checkSubStr(String input, int begin, int len) {
        if (len >= input.length()) {
            return false;
        }
        if (input.substring(len).contains(input.substring(begin, len))) {
            return true;
        } else {
            return checkSubStr(input, begin + 1, len + 1);
        }
    }

    /**
     * 计算坐标
     *
     * @param input
     */
    private static void calcCoor(String input) {
        if (null == input || "".equals(input)) {
            return;
        }
        String[] coors = input.split(";");
        int x = 0, y = 0;
        if (coors != null && coors.length > 0) {
            for (String str : coors) {
//                    System.out.print(str);
                if (str.matches("^[A-Z][0-9]{1,2}")) {
//                        System.out.println(str);
                    if (str.startsWith("A")) {
                        x = x - (Integer.parseInt(str.replace("A", "")));
                    } else if (str.startsWith("D")) {
                        x = x + (Integer.parseInt(str.replace("D", "")));
                    } else if (str.startsWith("W")) {
                        y = y + (Integer.parseInt(str.replace("W", "")));
                    } else if (str.startsWith("S")) {
                        y = y - Integer.parseInt(str.replace("S", ""));
                    }
                }
            }
            System.out.print(x + "," + y);
        }

    }

}
